<style>
	.layui-table-cell {
		padding:0 5px;
		height:auto;
		overflow:visible;
		text-overflow:inherit;
		white-space:normal;
		word-break: break-all;
	}
	.layui-table-cell{padding:1px 3px;line-height:20px;}
	.laytable-cell-1-0-0{text-align:center;}
	.layui-form-pane .layui-form-label{width:auto;}
	.layui-form-item{margin-bottom: 0px;}
	.order-time-bg{background-color:#1E9FFF;color:white;padding:0px 5px;}
	.material-status span,.material-status a{font-weight:bold;font-size:14px;}
	.fixed-bar-tr-header{
		z-index:2;
		margin-top: 25px;
		/*margin-top: 65px;*/
	}
</style>
<div class="fixed-bar">
	<form class="layui-form layui-form-pane fixed-bar-form" action="{:url()}" method="get" id="hisi-table-search-optable" >
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label">订单号</label>
				<div class="layui-input-inline">
					<input type="text" name="client_ordernum" lay-verify="" placeholder="输入订单号" class="layui-input">
				</div>
			</div>
            {if env('env_site') == 'riwei' }
            <div class="layui-inline">
                <label class="layui-form-label">客户单号</label>
                <div class="layui-input-inline">
                    <input type="text" name="ext_id" lay-verify="" placeholder="输入客户单号" class="layui-input">
                </div>
            </div>
            {/if}
			<div class="layui-inline removeStat">
				<label class="layui-form-label">SKU</label>
				<div class="layui-input-inline">
					<input type="text" name="sku" lay-verify="" placeholder="输入SKU" class="layui-input">
				</div>
			</div>
			<div class="layui-inline removeStat">
				<label class="layui-form-label">所属工厂</label>
				<div class="layui-input-inline">
					{:Form::select('factory_id', '', $factoryKV, '', '')}
				</div>
			</div>
			<div class="layui-inline removeStat">
				<label class="layui-form-label">下单日期</label>
				<div class="layui-input-inline">
					<input type="text" name="create_date_range" readonly="" id="create_date_range" lay-verify="" placeholder="选择下单日期" class="layui-input">
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label">订单状态</label>
				<div class="layui-input-inline">
					{:Form::select('order_status', '', ['' => '请选择', 1=>'未采购', 2=>'已采购', 3=>'已裁床', 4=>'已车缝', 5=>'已后整', 6=>'已出货', 7=>'已完成', 99=>'已废弃', 999=>'MES废除'], '', '')}
				</div>
			</div>
            <div class="layui-inline removeStat">
                  <label class="layui-form-label">账号</label>
                    <div class="layui-input-inline">
                        {:Form::select('is_auto_import', '', $orderFrom, '', '')}
                    </div>
            </div>
			<div class=" layui-inline layui-upload">
				<button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1" >搜索</button>
<!--				<button type="button" id="btn" class="layui-btn layui-btn-primary hisi-export prescription">导出</button>-->
				<a  href="javascript:void(0)" class="onclickReturnGoods layui-btn layui-btn-warm layui-btn-sm onclickReturnGoods-labelSet  ">自定义字段</a>
				<a href="" class="hisi-iframe onclickReturnGoods-hisi-iframe hide" title="自定义字段" hisi-data="{width: '660px', height: '600px'}" >自定义字段</a>
				<a href="{:url('getFile')}" class="hisi-iframe" title="下载已导出文件" hisi-data="{width: '860px', height: '600px'}" >下载已导出文件</a>

			</div>
		</div>
	</form>
</div>

<table id="dataTable" lay-filter='dataTable'></table>

{include file="system@block/layui" /}
<script type="text/html" id="picTpl">
	<span class="lay-pic-container" src="{{ d.pic }}">
		<img src="{{ d.ori_pic }}" class="lay-pic">
		{{# if(d.status==99){ }}
			<span class="sign"><img src="/static/system/image/sign_delete.png"></span>
		{{# }else if(d.status==2){ }}
			<span class="sign"><img src="/static/system/image/sign_over.png"></span>
		{{# }else if(d.tail_status==1){ }}
			<span class="sign"><img src="/static/system/image/sign_tail.png"></span>
		{{# }else if(d.chejian_status==1){ }}
			<span class="sign"><img src="/static/system/image/sign_workshop.png"></span>
		{{# }else if(d.caichuang_status==1){ }}
			<span class="sign"><img src="/static/system/image/sign_cutting.png"></span>
		{{# }else if(d.caigou_status==1){ }}
			<span class="sign"><img src="/static/system/image/sign_purchasing_done.png"></span>
		{{# }else { }}
			<span class="sign"><img src="/static/system/image/sign_purchasing_todo.png"></span>
		{{# } }}
	</span>
</script>
<script type="text/html" id="order_skuTpl">
	<span class="copy-item">{{ d.client_ordernum }}</span><br>
	{if env('env_site') == 'riwei' }
	<span class="copy-item">{{ d.ext_id }}</span> <br>
	{/if}
	<span class="copy-item">{{ d.sku }}</span> <br>
	{{ d.type }} <br>
	{{ d.create_time_diff }} <br>
	{{ d.create_time }} <br>
	{{ d.status }} <br>
	{{ d.is_auto_import }}
</script>
<script type="text/html" id="order_countTpl">
	出货数:<span title="出货数">{{ d.osStat.daohuo_count }}</span><br>
	车间数: <span title="车间数">{{ d.osStat.jiaohuo_count }}</span><br>
	裁床数:<span title="裁床数">{{ d.osStat.shicai_count }}</span><br>
	订单数量:<span title="订单数量">{{ d.quantity }}</span><br>

</script>
<script type="text/html" id="orderTimeTpl">
	<div class="{{# if(d.create_time !=''){ }}order-time-bg{{# } }}">下单：{{ d.create_time}}</div>
	<div class="{{# if(d.shipment_time !=''){ }}order-time-bg{{# } }}">货期：{{ d.shipment_time}}</div>
	<div class="{{# if(d.caigou_over_time !=''){ }}order-time-bg{{# } }}">采购：{{ d.caigou_over_time}}</div>
	<div class="{{# if(d.caichuang_over_time !=''){ }}order-time-bg{{# } }}">裁床：{{ d.caichuang_over_time}}</div>
	<div class="{{# if(d.chejian_over_time!=''){ }}order-time-bg{{# } }}">车间：{{ d.chejian_over_time}}</div>
	<div class="{{# if(d.tail_over_time !=''){ }}order-time-bg{{# } }}">尾部：{{ d.tail_over_time}}</div>
	<div class="{{# if(d.over_time !=''){ }}order-time-bg{{# } }}">总完：{{ d.over_time}}</div>
</script>
<script type="text/html" id="order_remarkTpl">
	备注:{{ d.remark }}<br>
	加工厂:{{ d.factory_name }}<br>
	产品分组:{{ d.group_name }}<br>
	外发工厂:{{ d.factory_outgo_name }}<br>
</script>
<script type="text/html" id="order_costTpl">
	加工费:{{ d.cost }}<br>
	售价:{{ d.price }}<br>
	货期:{{ d.shipment_time }}<br>
	是否公共款:{{ d.is_public }}<br>
	款式:{{ d.style_name }}<br>
	品类:{{ d.sku_type }}<br>
</script>
<script type="text/html" id="order_supplierTpl">
	面料供应商:{{ d.supplier }}<br>
	大烫:{{ d.off_pressing_level }}<br>
	是否新款:{{ d.is_new }}<br>
	裁剪方式:{{ d.caichuang_position }}<br>
</script>
<script type="text/html" id="order_special_processTpl">
	二次工艺A:{{ d.special_process_a_name }}<br>
	二次工艺A程度:{{ d.special_process_a_level }}<br>
	二次工艺B:{{ d.special_process_b_name }}<br>
	二次工艺B程度:{{ d.special_process_b_level }}<br>
	二次工艺C:{{ d.zj_name }}<br>
	二次工艺C程度:{{ d.zj_level }}<br>
</script>

<script type="text/html" id="orderNumTpl">
	{{# for(var i in d.osList){ }}
	{{ d.osList[i].size_name }}： <span title="下单数">{{ d.osList[i].order_count }}</span> / <span title="裁床数">{{ d.osList[i].shicai_count }}</span> / <span title="车间数">{{ d.osList[i].jiaohuo_count }}</span> / <span title="后整数">{{ d.osList[i].jiaohuo_tail_count }}</span> / <span title="打包数">{{ d.osList[i].delivery_count }}</span> / <span title="出货数">{{ d.osList[i].daohuo_count }}</span> <br>
	{{# } }}
	总数：<span title="总下单数">{{ d.osStat.order_count }}</span> / <span title="总裁床数">{{ d.osStat.shicai_count }}</span> / <span title="总车间数">{{ d.osStat.jiaohuo_count }}</span> / <span title="总后整数">{{ d.osStat.jiaohuo_tail_count }}</span> / <span title="总打包数">{{ d.osStat.delivery_count }}</span> / <span title="总出货数">{{ d.osStat.daohuo_count }}</span>
</script>

<script type="text/html" id="factoryTpl">
	{{ d.factory_name }} <br>
	{{ d.group_name }} <br>
	{{# if(d.outgo_status > 0){ }}
	外发：{{ d.factory_outgo_name }}
	{{# } }}

</script>

<script type="text/html" id="orderUserTpl">
	{{ d.caigou_user_name }} <br>
	{{ d.caichuang_user_name }}
</script>

<script type="text/html" id="material_nameTpl">
	{{ layui.tool.formatMaterialType( d.type_num , '', 2) }}
	<span class="copy-item"> {{ d.name }} </span> <br>
	sku：<span class="copy-item">{{ d.material_sku }}</span>
<!--	采购执行人:{{ d.caigou_user_name }}-->
</script>

<script type="text/javascript">
	layui.use(['upload', 'opTable', 'jquery', 'tool', 'laydate', 'layer', 'form', 'laytpl'], function() {
		var $ = layui.jquery;
		var laydate = layui.laydate;
		var laytpl = layui.laytpl;
		var layer = layui.layer;
		var form = layui.form;
        var upload = layui.upload;
		var table = layui.table;

		var opTable = layui.opTable.render({
			elem: '#dataTable'
			,url: '{:url()}' //数据接口
			,page: true //开启分页
			,skin: 'row'
			,even: true
			,limit: 20
			,limits: [20,50,100,150,200]
			,text: {
				none : '暂无相关数据'
			}
			,toolbar: '#toolbar'
			,defaultToolbar: ['filter', 'exports', 'print']
			,cols: [[ //表头
				{field:'pic',title : '图片', templet:'#picTpl',width:110}
				,{field:'col1',title : '订单号/SKU/类型/时效/下单时间/状态', templet:'#order_skuTpl',width:200}
				,{field:'col2',title : '出货数/车间数/裁床数/订单数量', templet:'#order_countTpl',width:200}
				,{field:'order_time',title : '时间进度', templet:'#orderTimeTpl',width:220}
				,{field:'col3',title : '备注/加工厂/产品分组/外发工厂',templet:'#order_remarkTpl',width:150}
				,{field:'col4',title : '加工费/售价/货期/是否公共款/款式/品类',templet:'#order_costTpl',width:150}
				,{field:'col5',title : '面料供应商/大烫/是否新款/裁剪方式',templet:'#order_supplierTpl',width:150}
				,{field:'col6',title : '二次工艺ABC信息与程度',templet:'#order_special_processTpl',width:150}
				// ,{field:'client_ordernum',title : '订单号/SKU/时效', templet:'#skuTpl',width:200}
				// ,{field:'factory_id',title : '工厂/分组', templet:'#factoryTpl',width:150}
				// ,{field:'order_num',title : '下单 / 裁床 / 车间 / 后整 / 打包 / 出货', templet:'#orderNumTpl',width:240}
				// ,{field:'order_user',title : '采购执行人/裁床执行人', templet:'#orderUserTpl'}
			]]
			//  展开的列配置
			,openTable: function (itemData) {
				return {
					elem: '#child' + itemData.LAY_INDEX
					,id: 'child' + itemData.LAY_INDEX
					,data: layui.tool.setDataToList(itemData, itemData.omList)
					,cellMinWidth: 100
					,limit: 20
					,toolbar: false
					//,defaultToolbar: ['filter', 'exports', 'print']
					,cols: [[
						{field: 'name', title: '材料名称',width:160,templet:'#material_nameTpl'}
						,{field:'supplier',title : '供应商',width:100,templet:function(d){return "<a href='javascript:void(0);' class='supplier' data-supplier='"+d.supplier+"' data-address='"+d.address+"' data-contact='"+d.contact+"'>"+d.supplier+"</a>";}}
						,{field:'model',title : '型号'}
						,{field:'material_dosage',title : '单件用量',width:60}
						,{field:'jing_material_dosage',title : '采购量',width:60}
						,{field:'purchasing_unit',title : '单位',width:40,templet:function(d){return d.purchasing_unit;}}
						,{field:'caigou_unitprice',title : '单价',width:60}
						,{field:'shiji_caigou_count',title : '实际采购量',width:60,templet:'#shijiCaigouTpl'}
						,{field:'tiaoshu',title : '条数',width:60}
						,{field:'st_operate_num',title : '材料使用明细',width:60}
						,{field:'st_remark',title : '材料使用操作',width:60}
						,{field:'caigou_over_time',title : '批色时间',width:100}
						,{field:'caigou_start_time',title : '采购时间',width:100}
						,{field:'tiaoshu_status_time_10',title : '换料中时间',width:100}
						,{field:'caigou_finish_time',title : '采购完成时间',width:100}
						,{field:'arrive_time',title : '到料时间',width:100}
						,{field:'caigou_confirm_time',title : '打标时间',width:100}
						,{field:'caigou_over_time',title : '批色通过时间',width:100}
						,{field:'caigou_over_time_2',title : '批色不通过时间',width:100}
						,{field:'send_goods_time',title : '已发货时间（物料进度）',width:100}
						,{field:'stock_in_time',title : '物料入库时间',width:100}
						,{field:'stock_out_time',title : '物料出库时间',width:100}
					]]
				}
			}
			,done: function(res, curr, count){
				opTable.openAll();
			}
		});

		/**
		 * layui非静态table搜索渲染
		 * @attr data-table table容器ID
		 * @attr hisi-data table基础参数
		 * @attr action 搜索请求地址
		 */
		$(document).on('submit', '#hisi-table-search-optable', function() {
			var that = $(this),
					arr = that.serializeArray(),
					where = new Array(),
					dataTable = that.attr('data-table') ? that.attr('data-table') : 'dataTable',
					options = new Function('return '+ that.attr('hisi-data'))() || {page: {curr:1}};

			for(var i in arr) {
				where[arr[i].name] = arr[i].value;
			}
			options.url = that.attr('action');
			options.where = where;
			opTable.reload(options);
			return false;
		});

        //数据统计弹窗操作over
		laydate.render({
		    elem: '#create_date_range'
		    ,range: '~'
		    ,theme: 'molv'
		    ,mark: {'{:$today}':''}
	    	,change: function(value, date, endDate){
		    	$('#create_date_range').val(value);
            	$('#layui-laydate1').remove();//关闭面板
            }
		});

		//自定义字段 点击
		$('.onclickReturnGoods-labelSet').click(function () {
			var url="{:url('mp/UserDefinedGet/labelSet')}";
			var formData= $('#hisi-table-search-optable').serialize();
			$('.onclickReturnGoods-hisi-iframe').attr('href',url+'?'+formData);
			$('.onclickReturnGoods-hisi-iframe').trigger('click');
		});
		// 供应商点击
		$(document).on('click','.supplier',function(){
			var content = $(this).attr('data-supplier') +"<br>"+ $(this).attr('data-contact') +"<br>"+ $(this).attr('data-address')
			layer.tips(content, this);
		});
	});

</script>